/**
 * 
 */
package com.zd.ticketing.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zd.common.bean.model.TicketInfo;
import com.zd.common.common.enums.StatusEnum;
import com.zd.common.dao.TicketInfoDao;
import com.zd.common.dao.common.BaseDao;
import com.zd.common.dao.common.FindRequestEntity;
import com.zd.common.dao.common.OrderEnum;
import com.zd.common.dao.common.WhereEnum;
import com.zd.common.service.impl.BaseServiceImpl;
import com.zd.ticketing.bean.vo.TicketInfoVo;
import com.zd.ticketing.service.ITicketInfoService;

/**
 * @author lishi
 * @date 2018年11月12日 下午6:58:12
 */
@Service
public class TicketInfoServiceImpl extends BaseServiceImpl<TicketInfo> implements ITicketInfoService {
	
	@Autowired
	private TicketInfoDao ticketInfoDao;
	
	
	@Override
	public BaseDao<TicketInfo> getBaseDao() {
		return ticketInfoDao;
	}


	@Override
	public List<TicketInfoVo> getScenicSpotTicketList(Integer scenicSpotId) throws Exception {
		FindRequestEntity findReq = new FindRequestEntity();
		findReq.addWhere("scenic_spot_id", WhereEnum.EQ, scenicSpotId);
		findReq.addWhere("status", WhereEnum.EQ, StatusEnum.valid.getKey());
		findReq.addWhere("end_time", WhereEnum.GE, new Date());
		findReq.addOrder("create_time", OrderEnum.ASC);
		List<TicketInfo> ticketInfoList = find(findReq);
		List<TicketInfoVo> ticketInfoVoList = new ArrayList<>();
		for (TicketInfo ticketInfo : ticketInfoList) {
			TicketInfoVo ticketInfoVo = new TicketInfoVo();
			BeanUtils.copyProperties(ticketInfo, ticketInfoVo);
			ticketInfoVoList.add(ticketInfoVo);
		}
		return ticketInfoVoList;
	}


	@Override
	public List<TicketInfo> getPCScenicSpotTicketList(Integer scenicSpotId) throws Exception {
		FindRequestEntity findReq = new FindRequestEntity();
		findReq.addWhere("scenic_spot_id", WhereEnum.EQ, scenicSpotId);
		findReq.addWhere("status", WhereEnum.EQ, StatusEnum.valid.getKey());
		findReq.addWhere("minimum_number", WhereEnum.EQ, 1);
		findReq.addWhere("end_time", WhereEnum.GE, new Date());
		findReq.addOrder("create_time", OrderEnum.ASC);
		return find(findReq);
	}
}
